<template>
  <div class="main">
    <!-- <video src="" class="video" /> -->
    <video data-v-c88d2986="" src="https://hm92api-1320582878.cos.ap-guangzhou.myqcloud.com/wuliu.mp4" autoplay="autoplay" loop="loop" muted="muted" style="width: 100%; height: 100%; object-fit: fill;" />

    <el-card class="box-card">
      <div class="img">
        <img src="https://slwl-admin.itheima.net/static/img/logo1.33ef7fa0.png" alt="">
      </div>
      <!-- form -->
      <div class="form">
        <el-form ref="loginForm" :model="loginForm" :rules="rules">
          <el-form-item prop="account">
            <el-input v-model="loginForm.account" class="inp" placeholder="账号" prefix-icon="el-icon-user" />
          </el-form-item>
          <el-form-item prop="password">
            <el-input v-model="loginForm.password" class="inp" placeholder="密码" prefix-icon="el-icon-unlock" show-password />
          </el-form-item>
          <el-form-item prop="code">
            <el-input v-model="loginForm.code" class="inp" placeholder="验证码" prefix-icon="el-icon-mobile" :suffix-icon="imgUrl" />
            <img :src="imgUrl" alt="" class="code" @click="getAuth">
          </el-form-item>
          <el-form-item>
            <el-button class="login-btn" @click="onSubmit">登录</el-button>
          </el-form-item>

        </el-form>
      </div>

    </el-card>

  </div>
</template>

<script>
import { auth, login } from '@/api/user'
export default {
  data() {
    return {
      imgUrl: '',
      loginForm: {
        account: 'demo',
        password: '888itcast.CN764%...',
        code: '',
        key: '1314'
      },
      rules: {
        account: [
          { required: true, message: '不能为空', trigger: 'blur' }
        ],
        password: [
          { required: true, message: '不能为空', trigger: 'blur' }
        ],
        code: [
          { required: true, message: '不能为空', trigger: 'blur' }
        ]
      }
    }
  },
  created() {
    this.getAuth()
  },
  methods: {
    async onSubmit() {
      await this.$refs.loginForm.validate()
      // 发送请求
      const { data } = await login(this.loginForm)
      // console.log(res)
      // 存储token
      this.$store.commit('user/SET_TOKEN', data.token.token)
      this.$message.success('登录成功')
      this.$router.push('/')
    },
    // 验证码
    async getAuth() {
      const res = await auth({ key: this.loginForm.key })
      // 将文件流图片转为地址
      this.imgUrl = window.URL.createObjectURL(res)
    }
  }
}
</script>

<style scoped lang="scss">
  .main{
    width: 100vw;
    height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    position: relative;
  }
  .code{
    position: absolute;
    right: 5px;
    height: 35px;
    top: 5%;
  }
  .img{
    text-align: center;
    img{
      width: 200px;
      height: 55px;
    }
  }
  .form{
    padding: 45px;
  }
  .text {
    font-size: 14px;
  }

  .item {
    padding: 18px 0;
  }

  .box-card {
    width: 480px;
    position: absolute;

  }
  .login-btn{
    width: 100%;
    height: 45px;
    background-color: #e15536;
    color: #fff;
    font-size: 18px;
  }
</style>
